<div class="p5 w600 h300">
<ul class="tab">
    <li id="one1" onClick="setTab('one',1,2)" class="hover">文件上传</li>
    <li id="one2" tab="2" onClick="setTab('one',2,2)" class="ku" type="jpg">文件选择</li>
</ul>
<div class="border h365 p5" style="overflow-y:auto">
<div id="con_one_1">
    <div id="uploadify">选择上传的附件</div>
    <div class="clear"></div>
    <div class="tipbox tipbox-warning">
        <div class="tipbox-icon"><i class="iconfont" title="警告">&#xF047;</i></div>
        <div class="tipbox-content">
            <h3 class="tipbox-title" >友情提示：每次上传只能上传一个文件</h3>
            <p class="tipbox-explain" id="progress"></p>
        </div>
    </div>    
    <div id="fileQueue"></div>
</div>
<div id="con_one_2" class="hide"></div>
</div>
</div>
<script type="text/javascript">
Do('Upload','Dialog',function(){
    $("#uploadify").uploadify({
        'swf':'__PUBLIC__/common/js/uploadify/uploadify.swf',
        'uploader':"{url('files/upload')}",
        'buttonText':'点击选择上传文件',
        'height':30,'width':120,'multi': false,
        'buttonCursor':'pointer','fileTypeDesc':'支持的格式：',
        'fileSizeLimit':'30MB',  //大小限制
        'formData': {"js_session_id":"{session_id()}"},
        'queueID': 'fileQueue',  //队列
        'onUploadProgress' : function(file,bytesUploaded, bytesTotal,totalBytesUploaded,totalBytesTotal) {//上传进度
            $('#progress').html('已上传 ' + totalBytesUploaded + ' 字节,共' + totalBytesTotal + ' 字节.');
        },
        'onUploadSuccess':function(file,data,response) {
            $('#' + file.id).find('.data').html(' 上传完毕');
            var json = jQuery.parseJSON(data);
            var msg = json.message;
            var rel = json.error;
            var url = json.url;
            if(rel == 1){
               $.dialog.alert(file.name+'---'+msg); 
            }else{
                var origin = artDialog.open.origin;
                var input = origin.document.getElementById('{$frameid}');
                input.value = url;
                input.select();
                $.dialog.close()
            }
        }
    });
    //获取最新上传
    $('.ku').click(function(){
        var targetUrl = '{url('files/lists',array("id"=>$frameid))}';
        var type = $(this).attr('type');
        var tab = $(this).attr('tab');
        $("#con_one_"+tab).empty();
        $("#con_one_"+tab).load(targetUrl,{type:type},function(){
            $('.pt').click(function(){//点击返回
                var origin = artDialog.open.origin;
                var aValue = $(this).attr("tpl");
                var input = origin.document.getElementById('{$frameid}');
                input.value = aValue;
                input.select();
                $.dialog.close()
            })
            $(".win").click(function(){
                var a=$(this).attr("uid");
                var b=$(this).attr("title");
                $.dialog.open(a,{opacity:0.20,title:b+' - CPCMS',lock:true,fixed:true})
            });
        });
    });
})
//Tab切换
function setTab(name,cursel,n){
    for(i=1;i<=n;i++){
        var menu=document.getElementById(name+i);
        var con=document.getElementById("con_"+name+"_"+i);
        menu.className=i==cursel?"hover":"";
        con.style.display=i==cursel?"block":"none";
    }
}
</script>